//分发饼⼲（easy）: https://leetcode.cn/problems/assign-cookies/
class Solution
{
public:
	int findContentChildren(vector<int>&g, vector<int>&s)
	{
		// 先排序
		sort(g.begin(), g.end());
		sort(s.begin(), s.end());
		// 利⽤双指针找答案
		int ret = 0, n = s.size();
		for (int i = 0, j = 0; i < g.size() && j < n; i++, j++)
		{
			while (j < n && s[j] < g[i])
			{
				j++; // 找饼⼲
			}

			if (j < n)
			{
				ret++;
			}
		}
		return ret;
	}
};
//最优除法（medium）: https://leetcode.cn/problems/optimal-division/
class Solution
{
public:
	string optimalDivision(vector<int>& nums)
	{
		int n = nums.size();
		// 先处理两个边界情况
		if (n == 1)
		{
			return to_string(nums[0]);
		}
		if (n == 2)
		{
			return to_string(nums[0]) + "/" + to_string(nums[1]);
		}
		string ret = to_string(nums[0]) + "/(" + to_string(nums[1]);
		for (int i = 2; i < n; i++)
		{
			ret += "/" + to_string(nums[i]);
		}
		ret += ")";
		return ret;
	}
};